package com.aiboleepro.base;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import java.io.Serializable;
import java.util.List;

/**
 * 通用的ServiceImpl
 *
 * @author aiboleepro
 * @date 2018-08-26 下午5:56
 **/
public abstract class BaseServiceImpl<T extends BaseObject, Id extends Serializable> implements BaseService<T, Id> {

    protected abstract BaseMapper<T> getMapper();

    @Override
    public List<T> selectAll() {
        return getMapper().selectAll();
    }

    @Override
    public List<T> select(T model) {
        return getMapper().select(model);
    }

    @Override
    public PageInfo<T> select(T model, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<T> list = getMapper().select(model);
        return new PageInfo<>(list);
    }

    @Override
    public T selectByPrimaryKey(Id id) {
        return getMapper().selectByPrimaryKey(id);
    }

    @Override
    public int selectCount(T model) {
        return getMapper().selectCount(model);
    }

    @Override
    public T selectOne(T model) {
        return getMapper().selectOne(model);
    }

    @Override
    public int delete(T model) {
        return getMapper().delete(model);
    }

    @Override
    public int deleteByPrimaryKey(Id id) {
        return getMapper().deleteByPrimaryKey(id);
    }

    @Override
    public boolean existsWithPrimaryKey(Id id) {
        return getMapper().existsWithPrimaryKey(id);
    }

    @Override
    public int insert(T model) {
        return getMapper().insert(model);
    }

    @Override
    public int insertList(List<T> list) {
        return getMapper().insertList(list);
    }

    @Override
    public int insertSelective(T model) {
        return getMapper().insertSelective(model);
    }

    @Override
    public int updateByPrimaryKey(T model) {
        return getMapper().updateByPrimaryKey(model);
    }

    @Override
    public int updateByPrimaryKeySelective(T model) {
        return getMapper().updateByPrimaryKeySelective(model);
    }
}
